package com.base.pig.poi.imports;


import com.base.pig.poi.ExcelUtils;
import com.base.pig.poi.common.PoiResult;
import com.base.pig.poi.handle.*;
import com.base.pig.poi.handle.rule.AbsSheetVerifyRule;
import com.base.pig.poi.imports.data.DeviceData;
import com.base.pig.poi.imports.data.LineData;
import com.base.pig.poi.imports.data.MonitorData;
import com.base.pig.poi.imports.data.PointData;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.function.Consumer;

public class ImportUtil {

    public static void main(String[] args) throws FileNotFoundException {
      //  parseMonitorSheet();
        //parseSensorSheet();

       // parseDeviceSheet(null);
    //  String  path="d:/11/DHX_POINT.xlsx";

       // FileInputStream    fis = new FileInputStream(path);
       // PoiResult<PointData>  ss=parsePointSheet(fis);
      //  System.out.println(ss);

        String  fileName= "DTX_POINT.xlsx";
        String[]  arr=fileName.split(".xls");
        System.out.println(arr[0]);
    }
    //导入监测点
    public static PoiResult<MonitorData>  parseMonitorSheet(InputStream is) {
        // 1. 导入规则定义
        Consumer<AbsSheetVerifyRule> columnRule = (rule) -> {


            rule.addRule("B", "pointID", "点位id", new StringHandler(false));
            rule.addRule("C", "pointName", "点位名称", new StringHandler(false));
            rule.addRule("D", "center_X", "X坐标", new DoubleHandler(false));
            rule.addRule("E", "center_Y", "y坐标", new DoubleHandler(false));
            rule.addRule("F", "center_Z", "z坐标", new DoubleHandler(true));
            rule.addRule("G", "pipeType", "类型", new StringHandler(false));


        };
        PoiResult<MonitorData> list = ExcelUtils.readSheet(
                is,
                MonitorData.class,
                columnRule,
                0,
                1,
                0, (row, rowNum) -> {
                    // 其他逻辑处理

                });
        return  list;
    }


    //导入设备
    public static PoiResult<DeviceData> parseDeviceSheet(InputStream is) {
        // 1. 导入规则定义
        Consumer<AbsSheetVerifyRule> columnRule = (rule) -> {
            //rule.addRule("A", "No", "序号", new StringHandler(false));
            rule.addRule("B", "pointID", "点位id", new StringHandler(false));
            rule.addRule("C", "pointName", "点位名称", new StringHandler(false));
            rule.addRule("D", "center_X", "x坐标", new DoubleHandler(false));
            rule.addRule("E", "center_Y", "y坐标", new DoubleHandler(false));
            rule.addRule("F", "center_Z", "高程", new DoubleHandler(true));
            rule.addRule("G", "pipeType", "类型", new StringHandler(false));
            rule.addRule("H", "snCode", "网关编号", new StringHandler(false));

            rule.addRule("I", "deviceTypeName", "设备类型名称", new StringHandler(false));
            rule.addRule("J", "slavecode", "从设备码", new StringHandler(true));
            rule.addRule("K", "netType", "订阅类型", new StringHandler(false));
            rule.addRule("L", "installTime", "安装时间", new DateHandler(false, "yyyy/MM/dd"));
            rule.addRule("M", "company", "厂家", new StringHandler(true));
            rule.addRule("N", "contact", "联系方式", new StringHandler(true));
            rule.addRule("O", "remarks", "备注", new StringHandler(true));

        };
        PoiResult<DeviceData> list = ExcelUtils.readSheet(
                 is,
                DeviceData.class,
                columnRule,
                0,
                1,
                0, (row, rowNum) -> {
                    // 其他逻辑处理
                    //1.组合devicid
                    String   slavecode_new ="";
                    if(row.getSlavecode()!=null){
                        slavecode_new=row.getSlavecode();
                    }
                    row.setDeviceID(row.getPointID()+row.getSnCode()+slavecode_new);
                    //2.设置时间格式  / /
                   // SimpleDateFormat simpleDateFormattime = new SimpleDateFormat("yyyy/MM/dd");
                   // String  dateString=simpleDateFormattime.format(row.getInstallTime());

                    //Date date = ft.parse(time)

                   // row.setInstallTime(date);

                });
         return  list;
    }



    //导入点
    public static PoiResult<PointData> parsePointSheet(InputStream is) {

        //**SmID	SmX	SmY	**SmLibTileID	**SmUserID	**OBJECTID	USERID
        //JGGG	PXJDH	JXZ	JSK	BSM	DM	WTDH
        //TSDH	GXDDM	TFH	XZB	YZB	DMGC
        //TZD	FSW	SZDL	JSDM	XZJ	JS
        //JGXZ	JGCZ	JGZJ	JGC	JGK	JXJCZ	JBS
        //JSZJ	QSDW	TCDW	TCRQ	BZ	NODEID	RKDATE
        //ISLOCK	US_ID	JSC	JGG	OBJECTID_	GDGC
        //FUHAO	XBILI	YBILI	ZBILI	XXUAN	YXUAN	ZXUAN

        // 1. 导入规则定义
        Consumer<AbsSheetVerifyRule> columnRule = (rule) -> {

            rule.addRule("B", "SmX", "SmX", new DoubleHandler(true));
            rule.addRule("C", "SmY", "SmY", new DoubleHandler(true));
            rule.addRule("G", "USERID", "USERID", new IntegerHandler(true));

            rule.addRule("H", "JGGG", "JGGG", new StringHandler(true));
            rule.addRule("I", "PXJDH", "PXJDH", new StringHandler(true));
            rule.addRule("J", "JXZ", "JXZ", new StringHandler(true));
            rule.addRule("K", "JSK", "JSK", new StringHandler(true));
            rule.addRule("L", "BSM", "BSM", new StringHandler(true));
            rule.addRule("M", "DM", "DM", new StringHandler(true));
            rule.addRule("N", "WTDH", "WTDH", new StringHandler(true));

            rule.addRule("O", "TSDH", "TSDH", new StringHandler(true));
            rule.addRule("P", "GXDDM", "GXDDM", new StringHandler(true));
            rule.addRule("Q", "TFH", "TFH", new StringHandler(true));
            rule.addRule("R", "XZB", "XZB", new StringHandler(true));
            rule.addRule("S", "YZB", "YZB", new StringHandler(true));
            rule.addRule("T", "DMGC", "DMGC", new StringHandler(true));

            rule.addRule("U", "TZD", "TZD", new StringHandler(true));
            rule.addRule("V", "FSW", "FSW", new StringHandler(true));
            rule.addRule("W", "SZDL", "SZDL", new StringHandler(true));
            rule.addRule("X", "JSDM", "JSDM", new StringHandler(true));
            rule.addRule("Y", "XZJ", "XZJ", new StringHandler(true));
            rule.addRule("Z", "JS", "JS", new StringHandler(true));

            rule.addRule("AA", "JGXZ", "JGXZ", new StringHandler(true));
            rule.addRule("AB", "JGCZ", "JGCZ", new StringHandler(true));
            rule.addRule("AC", "JGZJ", "JGZJ", new StringHandler(true));
            rule.addRule("AD", "JGC", "JGC", new StringHandler(true));
            rule.addRule("AE", "JGK", "JGK", new StringHandler(true));
            rule.addRule("AF", "JXJCZ", "JXJCZ", new StringHandler(true));
            rule.addRule("AG", "JBS", "JBS", new StringHandler(true));

            rule.addRule("AH", "JSZJ", "JSZJ", new StringHandler(true));
            rule.addRule("AI", "QSDW", "QSDW", new StringHandler(true));
            rule.addRule("AJ", "TCDW", "TCDW", new StringHandler(true));
            rule.addRule("AK", "TCRQ", "TCRQ", new StringHandler(true));
            rule.addRule("AL", "BZ", "BZ", new StringHandler(true));
            rule.addRule("AM", "NODEID", "NODEID", new StringHandler(true));
            rule.addRule("AN", "RKDATE", "RKDATE", new DateHandler(true, "yyyy/MM/dd"));

            rule.addRule("AO", "ISLOCK", "ISLOCK", new StringHandler(true));
            rule.addRule("AP", "US_ID", "US_ID", new StringHandler(true));
            rule.addRule("AQ", "JSC", "JSC", new StringHandler(true));
            rule.addRule("AR", "JGG", "JGG", new StringHandler(true));
            rule.addRule("AS", "OBJECTID_", "OBJECTID_", new DoubleHandler(true));
            rule.addRule("AT", "GDGC", "GDGC", new DoubleHandler(true));

            rule.addRule("AU", "FUHAO", "FUHAO", new DoubleHandler(true));
            rule.addRule("AV", "XBILI", "XBILI", new DoubleHandler(true));
            rule.addRule("AW", "YBILI", "YBILI", new DoubleHandler(true));
            rule.addRule("AX", "ZBILI", "ZBILI", new DoubleHandler(true));
            rule.addRule("AY", "XXUAN", "XXUAN", new DoubleHandler(true));
            rule.addRule("AZ", "YXUAN", "YXUAN", new DoubleHandler(true));

            rule.addRule("BA", "ZXUAN", "ZXUAN", new DoubleHandler(true));

        };
        PoiResult<PointData> list = ExcelUtils.readSheet(
                is,
                PointData.class,
                columnRule,
                0,
                1,
                0, (row, rowNum) -> {
                    // 其他逻辑处理
                    //1.组合devicid
                    //String   slavecode_new ="";
                    //if(row.getSlavecode()!=null){
                        //slavecode_new=row.getSlavecode();
                   // }
                   // row.setDeviceID(row.getPointID()+row.getSnCode()+slavecode_new);
                    //2.设置时间格式  / /
                    // SimpleDateFormat simpleDateFormattime = new SimpleDateFormat("yyyy/MM/dd");
                    // String  dateString=simpleDateFormattime.format(row.getInstallTime());

                    //Date date = ft.parse(time)

                    // row.setInstallTime(date);

                });
        return  list;
    }




    //导入线
    public static PoiResult<LineData> parseLineSheet(InputStream is) {

        //**SmID	SmKey	SmSdriW	SmSdriN	SmSdriE   SmSdriS	SmGranule
        //  SmGeometry	SmUserID	SmLibTileID   SmLength	SmTopoError	**OBJECTID	USERID
        // 	BSM  DM	QDDH	ZDDH	QDGC	ZDGC
        // QDMS	ZDMS   MSLX	CZ	GJ   DYZ
        //		YL	LX	ZKS   ZYKS  DLTS	BHCZ	XX
        //		GXFLDM	SZDL  QSDW  JSND	TCDW	TCRQ	SYZT
        // 	   BZ	SNODID	ENODID  RKDATE	ISLOCK  US_ID
        //		CD	OBJECTID_	SHAPE_LENG  FENGGE  	YANSE	KUANDU
        // 	STARTPOINT	ENDPOINT  LABEL  SHAPE_Length

        // 1. 导入规则定义
        Consumer<AbsSheetVerifyRule> columnRule = (rule) -> {

            //**SmID	SmKey	SmSdriW	SmSdriN	SmSdriE   SmSdriS	SmGranule
            rule.addRule("B", "SmKey", "SmKey", new IntegerHandler(true));
            rule.addRule("C", "SmSdriW", "SmSdriW", new DoubleHandler(true));
            rule.addRule("D", "SmSdriN", "SmSdriN", new DoubleHandler(true));
            rule.addRule("E", "SmSdriE", "SmSdriE", new DoubleHandler(true));
            rule.addRule("F", "SmSdriS", "SmSdriS", new DoubleHandler(true));
            rule.addRule("G", "SmGranule", "SmGranule", new DoubleHandler(true));

            //  **SmGeometry	SmUserID	SmLibTileID   SmLength	SmTopoError	OBJECTID	USERID
            rule.addRule("I", "SmUserID", "SmUserID", new IntegerHandler(true));
            rule.addRule("J", "SmLibTileID", "SmLibTileID", new LongHandler(true));
            rule.addRule("K", "SmLength", "SmLength", new DoubleHandler(true));
            rule.addRule("L", "SmTopoError", "SmTopoError", new IntegerHandler(true));
            rule.addRule("N", "USERID", "USERID", new IntegerHandler(true));


            //BSM  DM	QDDH	ZDDH	QDGC	ZDGC  QDMS	ZDMS
            rule.addRule("O", "BSM", "BSM", new StringHandler(true));
            rule.addRule("P", "DM", "DM", new StringHandler(true));
            rule.addRule("Q", "QDDH", "QDDH", new StringHandler(true));
            rule.addRule("R", "ZDDH", "ZDDH", new StringHandler(true));
            rule.addRule("S", "QDGC", "QDGC", new StringHandler(true));
            rule.addRule("T", "ZDGC", "ZDGC", new StringHandler(true));


            // QDMS	ZDMS   MSLX	CZ	GJ   DYZ
            rule.addRule("U", "QDMS", "QDMS", new StringHandler(true));
            rule.addRule("V", "ZDMS", "ZDMS", new StringHandler(true));
            rule.addRule("W", "MSLX", "MSLX", new StringHandler(true));
            rule.addRule("X", "CZ", "CZ", new StringHandler(true));
            rule.addRule("Y", "GJ", "GJ", new StringHandler(true));
            rule.addRule("Z", "DYZ", "DYZ", new StringHandler(true));

            //YL	LX	ZKS   ZYKS  DLTS	BHCZ	XX
            rule.addRule("AA", "YL", "YL", new StringHandler(true));
            rule.addRule("AB", "LX", "LX", new StringHandler(true));
            rule.addRule("AC", "ZKS", "ZKS", new StringHandler(true));
            rule.addRule("AD", "ZYKS", "ZYKS", new StringHandler(true));
            rule.addRule("AE", "DLTS", "DLTS", new StringHandler(true));
            rule.addRule("AF", "BHCZ", "BHCZ", new StringHandler(true));
            rule.addRule("AG", "XX", "XX", new StringHandler(true));


            //    //		GXFLDM	SZDL  QSDW  JSND	TCDW	TCRQ	SYZT
            rule.addRule("AH", "GXFLDM", "GXFLDM", new StringHandler(true));
            rule.addRule("AI", "SZDL", "SZDL", new StringHandler(true));
            rule.addRule("AJ", "QSDW", "QSDW", new StringHandler(true));
            rule.addRule("AK", "JSND", "JSND", new StringHandler(true));
            rule.addRule("AL", "TCDW", "TCDW", new StringHandler(true));
            rule.addRule("AM", "TCRQ", "TCRQ", new StringHandler(true));
            rule.addRule("AN", "SYZT", "SYZT", new StringHandler(true));


            // 	   BZ	SNODID	ENODID  RKDATE	ISLOCK  US_ID

            rule.addRule("AO", "BZ", "BZ", new StringHandler(true));
            rule.addRule("AP", "SNODID", "SNODID", new StringHandler(true));
            rule.addRule("AQ", "ENODID", "ENODID", new StringHandler(true));
            rule.addRule("AR", "RKDATE", "RKDATE",  new DateHandler(true, "yyyy/MM/dd"));
            rule.addRule("AS", "ISLOCK", "ISLOCK", new StringHandler(true));
            rule.addRule("AT", "US_ID", "US_ID", new StringHandler(true));

            //		CD	OBJECTID_	SHAPE_LENG  FENGGE  	YANSE	KUANDU

            rule.addRule("AU", "CD", "CD", new StringHandler(true));
            rule.addRule("AV", "OBJECTID_", "OBJECTID_", new DoubleHandler(true));
            rule.addRule("AW", "SHAPE_LENG", "SHAPE_LENG", new DoubleHandler(true));
            rule.addRule("AX", "FENGGE", "FENGGE", new DoubleHandler(true));
            rule.addRule("AY", "YANSE", "YANSE", new StringHandler(true));
            rule.addRule("AZ", "KUANDU", "KUANDU", new DoubleHandler(true));

            // 	STARTPOINT	ENDPOINT  LABEL  SHAPE_Length

            rule.addRule("BA", "STARTPOINT", "STARTPOINT", new DoubleHandler(true));
            rule.addRule("BB", "ENDPOINT", "ENDPOINT", new DoubleHandler(true));
            rule.addRule("BC", "LABEL", "LABEL", new StringHandler(true));
            rule.addRule("BD", "SHAPE_Length", "SHAPE_Length", new DoubleHandler(true));

        };
        PoiResult<LineData> list = ExcelUtils.readSheet(
                is,
                LineData.class,
                columnRule,
                0,
                1,
                0, (row, rowNum) -> {

                });
        return  list;
    }
}
